{template 'common/header-gw'}
<ol class="breadcrumb">
	<li><a href="./?refresh"><i class="fa fa-home"></i></a></li>
	<li><a href="{url 'account/display'}">公众号列表</a></li>
	<li class="active">编辑主公众号</li>
</ol>
<style>
	.nav-width li.active{width:25%;text-align:center;overflow:hidden;height:40px;}
	.nav-width .normal{background:#EEEEEE;width:25%;text-align:center;overflow:hidden;height:40px;}
	.guide em{font-style:normal; color:#d9534f;}
	.guide .list-group .list-group-item a{color:#07d;}
	.guide .list-group .list-group-item{padding-top:20px;}
	.guide .img{margin-bottom:15px; display:inline-block; border:1px solid #cccccc;padding:3px;}
	.guide .con{padding: 10px 30px;}
</style>

<ul class="nav nav-tabs nav-width">
	<li {if $_GPC['step']==1 || $_GPC['step']==''}class="active"{/if} class="normal"><a href="javascript:;">1. 账号基本信息</a></li>
	<li {if $_GPC['step']==2}class="active"{/if} class="normal"><a href="javascript:;">2. 一键获取公众号信息</a></li>
	<li {if $_GPC['step']==3}class="active"{/if} class="normal"><a href="javascript:;">3. 设置公众号信息</a></li>
	<li {if $_GPC['step']==4}class="active"{/if} class="normal"><a href="javascript:;">4. 引导页面</a></li>
</ul>

<div class="clearfix">
	{if $_GPC['step'] == 1}
	<form action="" method="post"  class="form-horizontal" role="form" id="form1">
		<input type="hidden" name="step" value="2">
		<div class="panel panel-default">
			<div class="panel-heading">
				基础信息
			</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">名称</label>
					<div class="col-sm-9 col-xs-12">
						<input disabled type="text" name="name" value="{$account['name']}" class="form-control" autocomplete="off">
						<span class="help-block">名称为了方便标识此公众号的作用及身份。可以为商户、组织或是公司的名称。</span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">描述</label>
					<div class="col-sm-9 col-xs-12">
						<textarea disabled style="height: 80px;" class="form-control" name="description">{$account['description']}</textarea>
						<span class="help-block">用于说明此公众号的功能及用途。</span>
					</div>
				</div>
				
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">引导关注素材</label>
					<div class="col-sm-9 col-xs-12">
						<input disabled type="text" name="bootstrap" value="{$bootstrap}" class="form-control" autocomplete="off">
						<span class="help-block">建议设置一条引导关注的素材,为空则跳转回测试起始界面。例:<a>点击查看</a></span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">当前服务套餐</label>
					<div class="col-sm-9 col-xs-12">
						<select disabled name="groupid" class="form-control">
							<option value="0" {if $account['groupid'] == 0} selected{/if} >基础服务</option>
							{if $_W['isfounder']}
								<option value="-1" {if $account['groupid'] == -1} selected{/if}>所有服务</option>
							{/if}
							{loop $group['package'] $item}
							<option {if $account['groupid'] == $item['id']} selected{/if} value="{$item['id']}">{$item['name']}</option>
							{/loop}
						</select>
						<span class="help-block">指定公众号可使用的功能及权限。基础服务包含系统模块使用权限。所有服务则表示拥有系统中全部权限。</span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">服务过期时间</label>
					<div class="col-sm-9 col-xs-12 disabled">
						<label for="p_radio_1" class="radio-inline "><input type="radio" name="isexpire" id="p_radio_1" value="1" disabled {if $groupdata['isexpire'] == '1'}checked{/if}/> 是</label>
						<label for="p_radio_2" class="radio-inline "><input type="radio" name="isexpire" id="p_radio_2" value="0" disabled {if $groupdata['isexpire'] == '0'}checked{/if}/> 否</label>
						<span class="help-block"></span>
					</div>
				</div>
				<div id="expirepanel" style="display:none">
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">过期时间</label>
						<div class="col-sm-9 col-xs-12">
							{php echo tpl_form_field_date('endtime', date('Y-m-d H:i',$groupdata['endtime']), true)}
							<span class="help-block">用户的使用时间过期时,只能使用'基础服务'服务套餐的功能。</span>
						</div>
					</div>
					{if $groupdata['oldgroupid'] !== ''}
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">过期前服务套餐</label>
							<div class="col-sm-9 col-xs-12">
								{if $groupdata['oldgroupid'] == 0}
									<input type="text" value="基础服务" readonly class="form-control">
								{elseif $groupdata['oldgroupid'] == -1}
									<input type="text" value="所有服务" readonly class="form-control">
								{else}
								{loop $group['package'] $item}
									{if $item['id'] == $groupdata['oldgroupid']}
									<input type="text" value="{$item['name']}" readonly class="form-control">
									{/if}
								{/loop}
								{/if}
								<span class="help-block">过期服务套餐是当前服务套餐过期后，系统保存的当前服务套餐的名称。</span>
							</div>
							<input type="hidden" name='groupidhide' value="{$account['groupid']}">
						</div>
					{/if}
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">短信剩余条数</label>
					<div class="col-sm-9 col-xs-12">
						<input disabled type="text" name="balance" id="balance" value="{$notify['sms']['balance']}" class="form-control" autocomplete="off">
						<span class="help-block">请填写短信剩余条数,必须为整数。</span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">短信签名</label>
					<div class="col-sm-9 col-xs-12">
						<input disabled type="text" name="signature" value="{$notify['sms']['signature']}" class="form-control" autocomplete="off">		
						<span class="help-block">请填写短信签名。</span>
					</div>
				</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-12">
				<input name="submit" type="submit" value="下一步" class="btn btn-primary col-lg-1" onlick="location.href={php echo url('account/post-acid', array('uniacid' => $uniacid))}"/>
				<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
		</div>
	</form>
	{elseif $_GPC['step']== 2 || $_GPC['step']== ''} 
	<form action="" method="post"  class="form-horizontal" role="form" enctype="multipart/form-data" id="form1">
		<input type="hidden" name="step" value="3">
		<input type="hidden" name="flag" value="1">
		<input type="hidden" name="uniacid" value="{$uniacid}">
		<div class="panel panel-default">
			<div class="panel-heading">
				一键获取公众号信息
			</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">类型</label>
					<div class="col-sm-9 col-xs-12">
						<label for="b_radio_3" class="radio-inline"><input type="radio" name="type" id="b_radio_3" value="1" {if empty($account['type']) || $account['type'] == 1}checked{/if} /> 微信</label>
						<label for="b_radio_4" class="radio-inline"><input type="radio" name="type" id="b_radio_4" value="2" {if $account['type'] == 2}checked{/if}/> 易信</label>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">公众登录用户</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="wxusername" id="username" class="form-control" value="{$account['username']}" autocomplete="off"/>
						<span class="help-block">请输入你的公众平台用户名</span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">公众登录密码</label>
					<div class="col-sm-9 col-xs-12">
						<input type="password" name="wxpassword" class="form-control" value="" autocomplete="off"  />
						<span class="help-block">请输入你的公众平台密码</span>
					</div>
				</div>
				<div class="form-group" style="display:none;">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">登录验证码</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="verify" class="txt grid-1 alpha pin form-control" value="" autocomplete="off" />
						<span class="help-inline"><img src="" id="imgverify"> <a href="javascript:;" id="toggle">换一张</a></span>
					</div>
				</div>
			</div>
		</div>
		<div class="form-group">
			<div class="col-sm-12">
				<input name="submit" type="submit" value="下一步" class="btn btn-primary col-lg-1" />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<a href="{php echo url('account/post-acid/', array('uniacid' => $uniacid, 'step' => 3))}" class="btn btn-default" />跳过</a>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<a href="{php echo url('account/post-acid/', array('uniacid' => $_GPC['uniacid'], 'step' => 1))}" class="btn btn-default" />上一步</a>
				<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
		</div>
	</form>
	{elseif $_GPC['step']==3}
	<form action="" method="post"  class="form-horizontal" role="form" enctype="multipart/form-data" id="form1">
		<input type="hidden" name="step" value="3">
		<input type="hidden" name="flag" value="2">
		
		<input type="hidden" name="uniacid" value="{$uniacid}">
		<input type="hidden" name="acid" value="{$acid}">
		<div class="panel panel-default">
			<div class="panel-heading">
				设置公众号信息
			</div>
			<div class="panel-body">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">类型</label>
					<div class="col-sm-9 col-xs-12">
						<label for="b_radio_3" class="radio-inline"><input type="radio" name="type" id="b_radio_3" value="1" {if empty($account['type']) || $account['type'] == 1}checked{/if} /> 微信</label>
						<label for="b_radio_4" class="radio-inline"><input type="radio" name="type" id="b_radio_4" value="2" {if $account['type'] == 2}checked{/if}/> 易信</label>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span> 公众号名称</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="name" class="form-control" value="{$account['name']}" autocomplete="off" />
						<span class="help-block">填写公众号的帐号名称</span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">公众号帐号</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="account" class="form-control" value="{$account['account']}" autocomplete="off" />
						<span class="help-block">填写公众号的帐号，一般为英文帐号</span>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">原始ID</label>
					<div class="col-sm-9 col-xs-12">
						<input type="text" name="original" class="form-control" value="{$account['original']}" autocomplete="off" />
						<span class="help-block">在给粉丝发送客服消息时,原始ID不能为空。建议您完善该选项</span>
					</div>
				</div>
				<div id="panel_1">
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">级别</label>
						<div class="col-sm-9 col-xs-12">
							<label for="status_1" class="radio-inline"><input autocomplete="off" type="radio" name="level" id="status_1" value="0" {if empty($account['level']) || $account['level']==1} checked{/if} > 普通订阅号</label>
							<label for="status_2" class="radio-inline"><input autocomplete="off" type="radio" name="level" id="status_2" value="1" {if $account['level']==2} checked{/if} /> 普通服务号</label>
							<label for="status_3" class="radio-inline"><input autocomplete="off" type="radio" name="level" id="status_3" value="2" {if $account['level']==3} checked{/if} /> 认证订阅号</label>
							<label for="status_4" class="radio-inline"><input autocomplete="off" type="radio" name="level" id="status_4" value="2" {if $account['level']==4} checked{/if} /> 认证服务号</label>
							<span class="help-block">注意：即使公众平台显示为“未认证”, 但只要【公众好设置】/【账号详情】下【认证情况】显示资质审核通过, 即可认定为认证号..</span>
						</div>
					</div>
					<div id="adv">
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">AppId</label>
							<div class="col-sm-9 col-xs-12">
								<input type="text" name="key" class="form-control" value="{$account['key']}" autocomplete="off"/>
								<div class="help-block">请填写微信公众平台后台的AppId</div>
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">AppSecret</label>
							<div class="col-sm-9 col-xs-12">
								<input type="text" name="secret" class="form-control" value="{$account['secret']}" autocomplete="off"/>
								<div class="help-block">请填写微信公众平台后台的AppSecret, 只有填写这两项才能管理自定义菜单</div>
							</div>
						</div>
						<div class="form-group">
							<label class="col-xs-12 col-sm-3 col-md-2 control-label">Oauth 2.0</label>
							<div class="col-sm-9 col-xs-12">
								<p class="form-control-static">在微信公众号请求用户网页授权之前，开发者需要先到公众平台网站的【开发者中心】<b>网页服务</b>中配置授权回调域名。<a href="http://www.we7.cc/manual/dev:v0.6:qa:mobile_redirect_url_error" target="_black">查看详情</a></p>
							</div>
						</div>
					</div>
				</div>
				<div id="panel_2">
				</div>
				{if !empty($acid)}
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label">接口地址</label>
						<div class="col-sm-9 col-xs-12">
							<input type="text" class="form-control" value="{$_W['siteroot']}api.php?id={$account['acid']}" readonly="readonly" autocomplete="off"/>
							<div class="help-block">设置“公众平台接口”配置信息中的接口地址</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label" style="color:red">Token</label>
						<div class="col-sm-9 col-xs-12">
							<div class="input-group">
								<input type="text" name="wetoken" class="form-control" value="{$account['token']}" readonly="readonly" />
								<span class="input-group-addon" style="cursor:pointer" onclick="tokenGen();">生成新的</span>
							</div>
							<div class="help-block">与公众平台接入设置值一致，必须为英文或者数字，长度为3到32个字符. 请妥善保管, Token 泄露将可能被窃取或篡改平台的操作数据.</div>
						</div>
					</div>
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label" style="color:red">EncodingAESKey</label>
						<div class="col-sm-9 col-xs-12">
							<div class="input-group">
								<input type="text" name="encodingaeskey" class="form-control" value="{$account['encodingaeskey']}" />
								<span class="input-group-addon" style="cursor:pointer" onclick="EncodingAESKeyGen();">生成新的</span>
							</div>
							<div class="help-block">与公众平台接入设置值一致，必须为英文或者数字，长度为43个字符. 请妥善保管, EncodingAESKey 泄露将可能被窃取或篡改平台的操作数据.</div>
						</div>
					</div>
				{/if}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">二维码</label>
					<div class="col-sm-9 col-xs-12">
						<input type="file" name="qrcode" value="{$item['qrcode']}">
						<span class="help-block">只支持JPG图片</span>
					</div>
				</div>
				{if file_exists(IA_ROOT . '/attachment/qrcode_'.$account['acid'].'.jpg')}
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
						<div class="col-sm-9 col-xs-12">
							<div class="input-group">
								<img src="{$_W[attachurl]}/qrcode_{$account['acid']}.jpg?time={php echo time()}" class="img-responsive img-thumbnail" width="150" />
							</div>
						</div>
					</div>
				{/if}
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">头像</label>
					<div class="col-sm-9 col-xs-12">
						<input type="file" name="headimg" value="{$item['headimg']}">
						<span class="help-block">只支持JPG图片</span>
					</div>
				</div>
				{if file_exists(IA_ROOT . '/attachment/headimg_'.$account['acid'].'.jpg')}
					<div class="form-group">
						<label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
						<div class="col-sm-9 col-xs-12">
							<div class="input-group">
								<img src="{$_W[attachurl]}/headimg_{$account['acid']}.jpg?time={php echo time()}" class="img-responsive img-thumbnail" width="150" />
							</div>
						</div>
					</div>
				{/if}
			</div>
		</div>
		
		<div class="form-group">
			<div class="col-sm-12">
				<input name="submit" type="submit" value="下一步" class="btn btn-primary col-lg-1" />
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				{if !empty($account)}
				{else}
					<a class="btn btn-default" href="{php echo url('account/post-acid/', array('uniacid' => $uniacid, 'step' => 2))}"/>返回上一步</a>
				{/if}
				<input type="hidden" name="token" value="{$_W['token']}" />
			</div>
		</div>
	</form>
	{elseif $_GPC['step']==4}
		<div class="panel panel-default guide">
			<div class="panel-heading">
				引导页面
			</div>
			<div class="panel-body">
				<h4 class="alert alert-info">您绑定的微信公众号：<em>{$account['name']}</em>； 请按下列引导完成配置。</h4>
				<div class="list-group">
					<div class="list-group-item">
						<h5 class="page-header">登录 <a href="https://mp.weixin.qq.com/" target="_blank">微信公众平台</a>，点击左侧菜单最后一项，进入 [ <em>开发者中心</em> ]</h5>
						<div class="con">
							<div class="img"><img src="resource/images/guide-01.png"/></div>
							<p># 如果您未成为开发者，请勾选页面上的同意协议，再点击 [ <em>成为开发者</em> ] 按钮</p>
						</div>
					</div>
					<div class="list-group-item">
						<h5 class="page-header">在开发者中心，找到［<em> 服务器配置</em> ］栏目下URL和Token设置</h5>
						<div class="con">
							<div class="img"><img src="resource/images/guide-02.png"/></div>
							<p># 将以下链接链接填入对应输入框：</p>
							<form action="" method="post" class="form-horizontal" role="form">
								<div class="form-group">
									<label class="col-xs-12 col-sm-2 col-md-1 col-lg-1 control-label">URL:</label>
									<div class="col-sm-9 input-group">
										<p class="form-control-static"><a href="javascript:;" title="点击复制接口地址">{$_W['siteroot']}api.php?id={$account['acid']}</a></p>
									</div>
								</div>
								<div class="form-group">
									<label class="col-xs-12 col-sm-2 col-md-1 col-lg-1 control-label">Token:</label>
									<div class="col-sm-9 input-group">
										<p class="form-control-static"> <a href="javascript:;" title="点击复制Token">{$account['token']}</a></p>
									</div>
								</div>
							</form>
							<p># 如果以前已填写过URL和Token，请点击[<em> 修改配置 </em>] ，再填写上述链接</p>
							<p># 请点击 [<em> 启用 </em>] ，以启用服务器配置：</p>
							<div class="img"><img src="resource/images/guide-03.png" width="524;"></div>
						</div>
					</div>
					<div class="list-group-item">
						<h5 class="page-header">
							{if $account['isconnect'] == 1}
								<em>公众号 {$account['name']} 接入成功</em>
							{else}
							
								<em>公众号 {$account['name']} 正在等待接入……请及时按照以上步骤操作接入公众平台</em>
							{/if}
						</h5>
						<div class="con">
							{if $account['isconnect'] == 0}
								<p># 检查公众平台配置</p>
								<p># 编辑公众号 <a href="{php echo url('account/bind/post', array('acid' => $acid, 'uniacid' => $account['uniacid']))}">{$account['name']}</a></p>
								<a href="javascript:window.location.reload();" class="btn btn-success" style="color:#FFF">检测是否接入成功</a>&nbsp;&nbsp;&nbsp;<a href="{php echo url('account/switch', array('uniacid' => $uniacid))}" class="btn btn-primary" style="color:#FFF">暂不接入，先去查看管理功能</a>
								<a href="{php echo url('')}" class="btn btn-info" style="color:#FFF">返回公众号列表</a>
							{else}
								<a href="{php echo url('account/switch', array('uniacid' => $uniacid))}" class="btn btn-primary" style="color:#FFF">管理公众号</a>
							{/if}
						</div>
					</div>
				</div>
			</div>
		</div>
	{/if}
</div>
<script type="text/javascript">
	require(['jquery', 'util', 'filestyle'], function($, u){
		$(function(){
			
			$('#expirepanel').css('display', $('input[name="isexpire"]:checked').val() == '1' ? '' : 'none');
			
			$('p.form-control-static a[href="javascript:;"]').each(function(){
				u.clip(this, $(this).text());
			});

			var codeurl = {'1':'https://mp.weixin.qq.com/cgi-bin/verifycode', '2':'https://plus.yixin.im/captcha'};
			$('#username').blur(function(){
				if ($('#username').val()) {
					var type = $('input[name="type"]:checked').val() ? $('input[name="type"]:checked').val() : 1;
					$('#imgverify').attr('src', codeurl[type] + '?username='+$('#username').val()+'&r='+Math.round(new Date().getTime()));
					$('#imgverify').parent().parent().parent().show();
					return false;
				}
			});
			$('#toggle').click(function(){
				if ($('#username').val()) {
					var type = $('input[name="type"]:checked').val() ? $('input[name="type"]:checked').val() : 1;
					$('#imgverify').attr('src', codeurl[type] + '?username='+$('#username').val()+'&r='+Math.round(new Date().getTime()));
					$('#imgverify').parent().parent().parent().show();
					return false;
				}
			});
			
			$(".form-group").find(':file').filestyle({buttonText: '上传图片'});
		
			$('div[id^="panel"]').hide();
			$('#panel_'+$('input:radio[name="type"]:checked').val()).show();
			$("input[name='type']").click(function(){
				$('div[id^="panel"]').hide();
				$('#panel_'+$(this).val()).show();
			});
		});
	});
	function tokenGen() {
		var letters = 'abcdefghijklmnopqrstuvwxyz0123456789';
		var token = '';
		for(var i = 0; i < 32; i++) {
			var j = parseInt(Math.random() * (31 + 1));
			token += letters[j];
		}
		$(':text[name="wetoken"]').val(token);
	}
	function EncodingAESKeyGen() {
		var letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
		var token = '';
		for(var i = 0; i < 43; i++) {
			var j = parseInt(Math.random() * 61 + 1);
			token += letters[j];
		}
		$(':text[name="encodingaeskey"]').val(token);
	}

</script>
{template 'common/footer-gw'}